home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / xmcd-1.4 / libdi.d / libdi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-10  |  9.6 KB  |  595 lines

  1. /*
  2.  *   libdi - CD Audio Player Device Interface Library
  3.  *
  4.  *   Copyright (C) 1995  Ti Kan
  5.  *   E-mail: ti@amb.org
  6.  *
  7.  *   This program is free software; you can redistribute it and/or modify
  8.  *   it under the terms of the GNU General Public License as published by
  9.  *   the Free Software Foundation; either version 2 of the License, or
  10.  *   (at your option) any later version.
  11.  *
  12.  *   This program is distributed in the hope that it will be useful,
  13.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *   GNU General Public License for more details.
  16.  *
  17.  *   You should have received a copy of the GNU General Public License
  18.  *   along with this program; if not, write to the Free Software
  19.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  *
  21.  */
  22. #ifndef LINT
  23. static char *_libdi_c_ident_ = "@(#)libdi.c    5.8 95/01/27";
  24. #endif
  25.  
  26. #include "common.d/appenv.h"
  27. #include "common.d/util.h"
  28. #include "libdi.d/libdi.h"
  29. #include "libdi.d/scsipt.h"
  30. #include "libdi.d/slioc.h"
  31.  
  32.  
  33. extern appdata_t    app_data;
  34.  
  35.  
  36. /* libdi module init routines */
  37. diinit_tbl_t        diinit[] = {
  38.     scsipt_init,            /* SCSI pass-through method */
  39.     slioc_init,            /* SunOS/Linux ioctl method */
  40.     NULL                /* List terminator */
  41. };
  42.  
  43.  
  44. /* libdi interface calling table */
  45. di_tbl_t        ditbl[MAX_METHODS];
  46.  
  47.  
  48. /*
  49.  * di_init
  50.  *    Top-level function to initialize the libdi modules.
  51.  *
  52.  * Args:
  53.  *    s - Pointer to the curstat_t structure
  54.  *
  55.  * Return:
  56.  *    Nothing.
  57.  */
  58. void
  59. di_init(curstat_t *s)
  60. {
  61.     int    i;
  62.  
  63. #if defined(DI_SCSIPT) && defined(DEMO_ONLY)
  64.     app_data.di_method = DI_SCSIPT;
  65. #else
  66.     /* Sanity check */
  67.     if (app_data.di_method < 0 || app_data.di_method >= MAX_METHODS) {
  68.         cd_fatal_popup(app_data.str_fatal, app_data.str_nomethod);
  69.         return;
  70.     }
  71. #endif
  72.  
  73.     /* Initialize the libdi modules */
  74.     for (i = 0; i < MAX_METHODS; i++) {
  75.         if (diinit[i].init != NULL)
  76.             diinit[i].init(s, &ditbl[i]);
  77.     }
  78.  
  79.     /* Sanity check again */
  80.     if (ditbl[app_data.di_method].mode == NULL) {
  81.         cd_fatal_popup(app_data.str_fatal, app_data.str_nomethod);
  82.         return;
  83.     }
  84. }
  85.  
  86.  
  87. /*
  88.  * di_check_disc
  89.  *    Check if disc is ready for use
  90.  *
  91.  * Args:
  92.  *    s - Pointer to the curstat_t structure
  93.  *
  94.  * Return:
  95.  *    TRUE - success
  96.  *    FALSE - failure
  97.  */
  98. bool_t
  99. di_check_disc(curstat_t *s)
  100. {
  101.     if (ditbl[app_data.di_method].check_disc != NULL)
  102.         return (ditbl[app_data.di_method].check_disc(s));
  103.  
  104.     return FALSE;
  105. }
  106.  
  107.  
  108. /*
  109.  * di_status_upd
  110.  *    Force update of playback status
  111.  *
  112.  * Args:
  113.  *    s - Pointer to the curstat_t structure
  114.  *
  115.  * Return:
  116.  *    Nothing.
  117.  */
  118. void
  119. di_status_upd(curstat_t *s)
  120. {
  121.     if (ditbl[app_data.di_method].status_upd != NULL)
  122.         ditbl[app_data.di_method].status_upd(s);
  123. }
  124.  
  125.  
  126. /*
  127.  * di_lock
  128.  *    Caddy lock function
  129.  *
  130.  * Args:
  131.  *    s - Pointer to the curstat_t structure
  132.  *    enable - whether to enable/disable caddy lock
  133.  *
  134.  * Return:
  135.  *    Nothing.
  136.  */
  137. void
  138. di_lock(curstat_t *s, bool_t enable)
  139. {
  140.     if (ditbl[app_data.di_method].lock != NULL)
  141.         ditbl[app_data.di_method].lock(s, enable);
  142. }
  143.  
  144.  
  145. /*
  146.  * di_repeat
  147.  *    Repeat mode function
  148.  *
  149.  * Args:
  150.  *    s - Pointer to the curstat_t structure
  151.  *    enable - whether to enable/disable repeat mode
  152.  *
  153.  * Return:
  154.  *    Nothing.
  155.  */
  156. void
  157. di_repeat(curstat_t *s, bool_t enable)
  158. {
  159.     if (ditbl[app_data.di_method].repeat != NULL)
  160.         ditbl[app_data.di_method].repeat(s, enable);
  161. }
  162.  
  163.  
  164. /*
  165.  * di_shuffle
  166.  *    Shuffle mode function
  167.  *
  168.  * Args:
  169.  *    s - Pointer to the curstat_t structure
  170.  *    enable - whether to enable/disable shuffle mode
  171.  *
  172.  * Return:
  173.  *    Nothing.
  174.  */
  175. void
  176. di_shuffle(curstat_t *s, bool_t enable)
  177. {
  178.     if (ditbl[app_data.di_method].shuffle != NULL)
  179.         ditbl[app_data.di_method].shuffle(s, enable);
  180. }
  181.  
  182.  
  183. /*
  184.  * di_load_eject
  185.  *    CD caddy load and eject function.  If disc caddy is not
  186.  *    loaded, it will attempt to load it.  Otherwise, it will be
  187.  *    ejected.
  188.  *
  189.  * Args:
  190.  *    s - Pointer to the curstat_t structure
  191.  *
  192.  * Return:
  193.  *    Nothing.
  194.  */
  195. void
  196. di_load_eject(curstat_t *s)
  197. {
  198.     if (ditbl[app_data.di_method].load_eject != NULL)
  199.         ditbl[app_data.di_method].load_eject(s);
  200. }
  201.  
  202.  
  203. /*
  204.  * di_ab
  205.  *    A->B segment play mode function
  206.  *
  207.  * Args:
  208.  *    s - Pointer to the curstat_t structure
  209.  *
  210.  * Return:
  211.  *    Nothing.
  212.  */
  213. void
  214. di_ab(curstat_t *s)
  215. {
  216.     if (ditbl[app_data.di_method].ab != NULL)
  217.         ditbl[app_data.di_method].ab(s);
  218. }
  219.  
  220.  
  221. /*
  222.  * di_sample
  223.  *    Sample play mode function
  224.  *
  225.  * Args:
  226.  *    s - Pointer to the curstat_t structure
  227.  *
  228.  * Return:
  229.  *    Nothing.
  230.  */
  231. void
  232. di_sample(curstat_t *s)
  233. {
  234.     if (ditbl[app_data.di_method].sample != NULL)
  235.         ditbl[app_data.di_method].sample(s);
  236. }
  237.  
  238.  
  239. /*
  240.  * di_level
  241.  *    Audio volume control function
  242.  *
  243.  * Args:
  244.  *    s - Pointer to the curstat_t structure
  245.  *    level - The volume level to set to
  246.  *    drag - Whether this is an update due to the user dragging the
  247.  *        volume control slider thumb.  If this is FALSE, then
  248.  *        a final volume setting has been found.
  249.  *
  250.  * Return:
  251.  *    Nothing.
  252.  */
  253. void
  254. di_level(curstat_t *s, byte_t level, bool_t drag)
  255. {
  256.     if (ditbl[app_data.di_method].level != NULL)
  257.         ditbl[app_data.di_method].level(s, level, drag);
  258. }
  259.  
  260.  
  261. /*
  262.  * di_play_pause
  263.  *    Audio playback and pause function
  264.  *
  265.  * Args:
  266.  *    s - Pointer to the curstat_t structure
  267.  *
  268.  * Return:
  269.  *    Nothing.
  270.  */
  271. void
  272. di_play_pause(curstat_t *s)
  273. {
  274.     if (ditbl[app_data.di_method].play_pause != NULL)
  275.         ditbl[app_data.di_method].play_pause(s);
  276. }
  277.  
  278.  
  279. /*
  280.  * di_stop
  281.  *    Stop function
  282.  *
  283.  * Args:
  284.  *    s - Pointer to the curstat_t structure
  285.  *    stop_disc - Whether to actually spin down the disc or just
  286.  *        update status.
  287.  *
  288.  * Return:
  289.  *    Nothing.
  290.  */
  291. void
  292. di_stop(curstat_t *s, bool_t stop_disc)
  293. {
  294.     if (ditbl[app_data.di_method].stop != NULL)
  295.         ditbl[app_data.di_method].stop(s, stop_disc);
  296. }
  297.  
  298.  
  299. /*
  300.  * di_prevtrk
  301.  *    Previous track function
  302.  *
  303.  * Args:
  304.  *    s - Pointer to the curstat_t structure
  305.  *
  306.  * Return:
  307.  *    Nothing.
  308.  */
  309. void
  310. di_prevtrk(curstat_t *s)
  311. {
  312.     if (ditbl[app_data.di_method].prevtrk != NULL)
  313.         ditbl[app_data.di_method].prevtrk(s);
  314. }
  315.  
  316.  
  317. /*
  318.  * di_nexttrk
  319.  *    Next track function
  320.  *
  321.  * Args:
  322.  *    s - Pointer to the curstat_t structure
  323.  *
  324.  * Return:
  325.  *    Nothing.
  326.  */
  327. void
  328. di_nexttrk(curstat_t *s)
  329. {
  330.     if (ditbl[app_data.di_method].nexttrk != NULL)
  331.         ditbl[app_data.di_method].nexttrk(s);
  332. }
  333.  
  334.  
  335. /*
  336.  * di_previdx
  337.  *    Previous index function
  338.  *
  339.  * Args:
  340.  *    s - Pointer to the curstat_t structure
  341.  *
  342.  * Return:
  343.  *    Nothing.
  344.  */
  345. void
  346. di_previdx(curstat_t *s)
  347. {
  348.     if (ditbl[app_data.di_method].previdx != NULL)
  349.         ditbl[app_data.di_method].previdx(s);
  350. }
  351.  
  352.  
  353. /*
  354.  * di_nextidx
  355.  *    Next index function
  356.  *
  357.  * Args:
  358.  *    s - Pointer to the curstat_t structure
  359.  *
  360.  * Return:
  361.  *    Nothing.
  362.  */
  363. void
  364. di_nextidx(curstat_t *s)
  365. {
  366.     if (ditbl[app_data.di_method].nextidx != NULL)
  367.         ditbl[app_data.di_method].nextidx(s);
  368. }
  369.  
  370.  
  371. /*
  372.  * di_rew
  373.  *    Search-rewind function
  374.  *
  375.  * Args:
  376.  *    s - Pointer to the curstat_t structure
  377.  *
  378.  * Return:
  379.  *    Nothing.
  380.  */
  381. void
  382. di_rew(curstat_t *s, bool_t start)
  383. {
  384.     if (ditbl[app_data.di_method].rew != NULL)
  385.         ditbl[app_data.di_method].rew(s, start);
  386. }
  387.  
  388.  
  389. /*
  390.  * di_ff
  391.  *    Search-fast-forward function
  392.  *
  393.  * Args:
  394.  *    s - Pointer to the curstat_t structure
  395.  *
  396.  * Return:
  397.  *    Nothing.
  398.  */
  399. void
  400. di_ff(curstat_t *s, bool_t start)
  401. {
  402.     if (ditbl[app_data.di_method].ff != NULL)
  403.         ditbl[app_data.di_method].ff(s, start);
  404. }
  405.  
  406.  
  407. /*
  408.  * di_warp
  409.  *    Track warp function
  410.  *
  411.  * Args:
  412.  *    s - Pointer to the curstat_t structure
  413.  *
  414.  * Return:
  415.  *    Nothing.
  416.  */
  417. void
  418. di_warp(curstat_t *s)
  419. {
  420.     if (ditbl[app_data.di_method].warp != NULL)
  421.         ditbl[app_data.di_method].warp(s);
  422. }
  423.  
  424.  
  425. /*
  426.  * di_route
  427.  *    Channel routing function
  428.  *
  429.  * Args:
  430.  *    s - Pointer to the curstat_t structure
  431.  *
  432.  * Return:
  433.  *    Nothing.
  434.  */
  435. void
  436. di_route(curstat_t *s)
  437. {
  438.     if (ditbl[app_data.di_method].route != NULL)
  439.         ditbl[app_data.di_method].route(s);
  440. }
  441.  
  442.  
  443. /*
  444.  * di_mute_on
  445.  *    Mute audio function
  446.  *
  447.  * Args:
  448.  *    s - Pointer to the curstat_t structure
  449.  *
  450.  * Return:
  451.  *    Nothing.
  452.  */
  453. void
  454. di_mute_on(curstat_t *s)
  455. {
  456.     if (ditbl[app_data.di_method].mute_on != NULL)
  457.         ditbl[app_data.di_method].mute_on(s);
  458. }
  459.  
  460.  
  461. /*
  462.  * di_mute_off
  463.  *    Un-mute audio function
  464.  *
  465.  * Args:
  466.  *    s - Pointer to the curstat_t structure
  467.  *
  468.  * Return:
  469.  *    Nothing.
  470.  */
  471. void
  472. di_mute_off(curstat_t *s)
  473. {
  474.     if (ditbl[app_data.di_method].mute_off != NULL)
  475.         ditbl[app_data.di_method].mute_off(s);
  476. }
  477.  
  478.  
  479. /*
  480.  * di_start
  481.  *    Start the SCSI pass-through module.
  482.  *
  483.  * Args:
  484.  *    s - Pointer to the curstat_t structure
  485.  *
  486.  * Return:
  487.  *    Nothing.
  488.  */
  489. void
  490. di_start(curstat_t *s)
  491. {
  492.     if (ditbl[app_data.di_method].start != NULL)
  493.         ditbl[app_data.di_method].start(s);
  494. }
  495.  
  496.  
  497. /*
  498.  * di_icon
  499.  *    Handler for main window iconification/de-iconification
  500.  *
  501.  * Args:
  502.  *    s - Pointer to the curstat_t structure
  503.  *    iconified - Whether the main window is iconified
  504.  *
  505.  * Return:
  506.  *    Nothing.
  507.  */
  508. void
  509. di_icon(curstat_t *s, bool_t iconified)
  510. {
  511.     if (ditbl[app_data.di_method].icon != NULL)
  512.         ditbl[app_data.di_method].icon(s, iconified);
  513. }
  514.  
  515.  
  516. /*
  517.  * di_halt
  518.  *    Shut down the SCSI pass-through and vendor-unique modules.
  519.  *
  520.  * Args:
  521.  *    s - Pointer to the curstat_t structure
  522.  *
  523.  * Return:
  524.  *    Nothing.
  525.  */
  526. void
  527. di_halt(curstat_t *s)
  528. {
  529.     if (ditbl[app_data.di_method].halt != NULL)
  530.         ditbl[app_data.di_method].halt(s);
  531. }
  532.  
  533.  
  534. /*
  535.  * di_mode
  536.  *    Return a text string indicating the current operating mode.
  537.  *
  538.  * Args:
  539.  *    Nothing.
  540.  *
  541.  * Return:
  542.  *    Mode text string.
  543.  */
  544. char *
  545. di_mode(void)
  546. {
  547.     if (ditbl[app_data.di_method].mode != NULL)
  548.         return (ditbl[app_data.di_method].mode());
  549.  
  550.     return ("");
  551. }
  552.  
  553.  
  554. /*
  555.  * di_vers
  556.  *    Return a text string indicating active module's version number
  557.  *
  558.  * Args:
  559.  *    Nothing.
  560.  *
  561.  * Return:
  562.  *    Version text string.
  563.  */
  564. char *
  565. di_vers(void)
  566. {
  567.     if (ditbl[app_data.di_method].vers != NULL)
  568.         return (ditbl[app_data.di_method].vers());
  569.  
  570.     return ("");
  571. }
  572.  
  573.  
  574. /*
  575.  * di_isdemo
  576.  *    Query if this is a demo-only version of the CD player.
  577.  *
  578.  * Args:
  579.  *    Nothing.
  580.  *
  581.  * Return:
  582.  *    TRUE - demo-only version.
  583.  *    FALSE - real version.
  584.  */
  585. bool_t
  586. di_isdemo(void)
  587. {
  588. #ifdef DEMO_ONLY
  589.     return TRUE;
  590. #else
  591.     return FALSE;
  592. #endif
  593. }
  594.  
  595.